package com.quarantine.web.admin;

import org.apache.commons.lang.xwork.StringUtils;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;

import com.quarantine.model.staticmessage;
import com.quarantine.service.StaticmessageManager;
import com.quarantine.util.DateUtils;
import com.quarantine.web.CrudActionSupport;

@Namespace("/admin")
@Results({
	@Result(name ="save", location = "staticmessage-admin!show.action", type ="redirect" ,params={"type","${type}","id","${id}"})
})
public class StaticmessageAdminAction extends CrudActionSupport<staticmessage> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private staticmessage entity;
	private StaticmessageManager staticmessage;
	private String id;
	private String type;
	private String category;

	@Override
	public staticmessage getModel() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String list() throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String input() throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String save() throws Exception {
         if(type.equals("1")){
        	 entity.setCategory("联系我们");//联系我们（1）；入会程序（2）；收费标准（3）的存储
         }
         if(type.equals("2")){
        	 entity.setCategory("入会程序");//联系我们（1）；入会程序（2）；收费标准（3）的存储
         }
         if(type.equals("3")){
        	 entity.setCategory("收费标准");//联系我们（1）；入会程序（2）；收费标准（3）的存储
         }
         if(type.equals("4")){
        	 entity.setCategory("分会概况");//联系我们（1）；入会程序（2）；收费标准（3）的存储
         }
         entity.setEditTime(DateUtils.now());
         staticmessage.save(entity);
		return "save";
	}
	public String show() {
		if(type.equals("1")){
			category="联系我们";
       	 entity=staticmessage.getByCategory(category);//联系我们（1）；入会程序（2）；收费标准（3）；分会概况（4）的存储
        }
        if(type.equals("2")){
        	category="入会程序";
        	entity=staticmessage.getByCategory(category);//联系我们（1）；入会程序（2）；收费标准（3）；分会概况（4—）的存储
        }
        if(type.equals("3")){
        	category="收费标准";
        entity=	staticmessage.getByCategory(category);//联系我们（1）；入会程序（2）；收费标准（3）；分会概况（4）的存储
        }
        if(type.equals("4")){
        	category="分会概况";
        entity=	staticmessage.getByCategory(category);//联系我们（1）；入会程序（2）；收费标准（3）；分会概况（4）的存储
        }
		return "amend";
	}
	public String edit() {
		if(type.equals("1")){
			category="联系我们";
       	 entity=staticmessage.getByCategory(category);//联系我们（1）；入会程序（2）；收费标准（3）；分会概况（4）的存储
        }
        if(type.equals("2")){
        	category="入会程序";
        	entity=staticmessage.getByCategory(category);//联系我们（1）；入会程序（2）；收费标准（3）；分会概况（4—）的存储
        }
        if(type.equals("3")){
        	category="收费标准";
        entity=	staticmessage.getByCategory(category);//联系我们（1）；入会程序（2）；收费标准（3）；分会概况（4）的存储
        }
        if(type.equals("4")){
        	category="分会概况";
        entity=	staticmessage.getByCategory(category);//联系我们（1）；入会程序（2）；收费标准（3）；分会概况（4）的存储
        }
		return "edit";
	}
	@Override
	public String delete() throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	protected void prepareModel() throws Exception {
		if (StringUtils.isEmpty(id)) {
			entity = new staticmessage();
		} else {
			entity = staticmessage.getById(id);
		}
	}

	public staticmessage getEntity() {
		return entity;
	}

	public void setEntity(staticmessage entity) {
		this.entity = entity;
	}

	

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public StaticmessageManager getStaticmessage() {
		return staticmessage;
	}
    @Autowired
	public void setStaticmessage(StaticmessageManager staticmessage) {
		this.staticmessage = staticmessage;
	}

	public String getCategory() {
		return category;
	}

	public void setCategory(String category) {
		this.category = category;
	}

}
